import time
import functools


def metric(fn):
    @functools.wraps(fn)
    def time_metric(*args, **kw):
        start_time = time.time()
        fn(*args, **kw)
        end_time = time.time()

        print('耗时：{:.4f}s'.format(end_time - start_time), start_time, end_time)

    return time_metric


@metric
def addition_func(x):
    """
    Do some math.
    """
    time.sleep(x)
    print('运行结束了')


addition_func(3)
# import functools
# import time
#
#
# def run_time(fn):
#     @functools.wraps(fn)
#     def wrapper(*args, **kw):
#         start = time.time()
#         res = fn(*args, **kw)
#         print('%s 运行了 %f 秒' % (fn.__name__, time.time() - start))
#         return res
#
#     return wrapper
#
#
# # 测试
# @run_time
# def test(n):
#     time.sleep(n)
#     print("运行结束了")
#
#
# test(3)
